import { PLUS_LIST } from 'boot/menu.js'
import DemoPage from 'components/DemoPage.vue'

// 文档页面组件
// - @name 文档名
// - @props 组件参数
function docPage (name, props) {
  return import('pages/doc/' + name + '.md').then(doc => ({
    extends: DemoPage,
    props: {
      doc: {
        type: String,
        default: () => doc.default
      },
      ...props
    }
  }))
}

const routes = [
  {
    path: '/',
    component: () => import('layouts/MainLayout.vue'),
    children: [
      { path: '/', component: () => import('pages/Index.vue') },
      {
        path: '/Install',
        component: () => docPage('Install')
      },
      {
        path: '/QuasarComponents/:category?',
        component: () => import('pages/QuasarComponents.vue')
      },
      {
        path: '/QuasarIconSets/:iconSet?',
        component: () => import('pages/QuasarIconSets.vue')
      },
      {
        path: '/CustomIconSets/:iconSet?',
        component: () => import('pages/CustomIconSets.vue')
      },
      ...PLUS_LIST.map((item, index) => ({
        path: item.to,
        component: () =>
          docPage(item.caption, {
            prevPage: {
              type: String,
              default: (PLUS_LIST[index - 1] || {}).to || '/'
            },
            nextPage: {
              type: String,
              default: (PLUS_LIST[index + 1] || {}).to || '/'
            }
          })
      }))
    ]
  },

  // Always leave this as last one,
  // but you can also remove it
  {
    path: '*',
    component: () => import('pages/Error404.vue')
  }
]

export default routes
